/**
 * Created with File
 * Author: Chuans
 * Github: https://github.com/chuans
 * Date: 2018/9/7
 * Time: 下午4:59
 */

import {observable, action, runInAction} from 'mobx';
import http from '../../util/axios';
import APIS from '../../config/apis';


class Notification {
    // 数据列表
    @observable public list: Table.Data[] = [];

    // 保留搜索状态
    @observable public searchStatus: Table.Values = {
        pageIndex: 1,
        pageSize: 10,
    };

    // 存放详情原始数据
    @observable public details: any = {};

    @observable public total: number = 1;

    // 是否在加载中
    @observable public listLoading: boolean = false;

    // 加载列表
    @action public getList = async (values: Table.Values) => {
        this.listLoading = true;

        const result = await http.get(APIS.NOTIFICATION_READ_LIST, values);


        if (result.code !== 0) {
            runInAction(() => {
                this.listLoading = false;
            })
            return result.message;
        }
        runInAction(() => {
            const {data, total} = result.data;

            this.listLoading = false;
            this.list = data;
            this.total = total;
            this.searchStatus = values;
        })
    }

}

export default new Notification();
